<script src="prototype-1.6.0.2.js"></script>

<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />

<script>

function update_contents_by_url(div, pars, url) {

  //alert(pars);
  //var url = 'proxy.rb';
  var myAjax = new Ajax.Updater(
    div, 
    url, 
    {
      method: 'post', 
      parameters: pars
      //onComplete: 
    }
  );
  //$(div).innerHTML = div;
  //alert(pars);
  //$(div).innerHTML = "<p align='center'>只今、データを読み込んでいます。<br>しばらくお待ち下さい。</p>";
}

function update_contents(div, pars) {
  update_contents_by_url(div, pars, 'proxy.rb');
}

flg_add_form = true;

function update_contents_by_form(div, fm) {
  //alert(div);
  pars = Form.serialize(fm);
  update_contents(div, pars);
  update_sidebar();
  if (div=="item_0") {
    if (flg_add_form) {
      Form.disable("frm_add_item");
      flg_add_form = false;
    } else {
      Form.enable("frm_add_item");
      flg_add_form = true;
    }
  }
}

function update_sidebar() {
  pars = "mode=sidebar";
  div = "sidebar";
  update_contents(div, pars);
}

function change_display(id) {
  if(document.getElementById(id).style.display == 'none'){
    document.getElementById(id).style.display = 'block';
  }else{
    document.getElementById(id).style.display = 'none';
  }
}

function set_display_block(id) {
    document.getElementById(id).style.display = 'block';
}

function get_change_filename_form(filename) {
  div = filename;
  pars = "mode=edit&file=" + filename;
  url = document.URL;
  update_contents_by_url(div, pars, url);
}

function update_filename_by_form(filename, fm) {
  div = filename;
  pars = Form.serialize(fm);
  url = document.URL;
  update_contents_by_url(div, pars, url);
  location.reload();
}

function get_delete_file_form(filename) {
  div = filename;
  pars = "mode=conf&file=" + filename;
  url = document.URL;
  update_contents_by_url(div, pars, url);
}

function delete_file_by_form(filename, fm) {
  div = filename;
  pars = Form.serialize(fm);
  url = document.URL;
  update_contents_by_url(div, pars, url);
  location.reload();
}

function file_operation_cancel(filename) {
  div = filename;
  pars = "mode=cancel&file=" + filename;
  url = document.URL;
  update_contents_by_url(div, pars, url);
}

function insert_selected_image(fm) {
  if (fm.images.value != "") {
    //alert(fm.contents.value);
    html = "<img src='../html/images/" + fm.images.value + "' />";
    fm.contents.value += html;
    //alert(html);
  }
}

function insert_selected_file(fm) {
  if (fm.files.value != "") {
    //alert(fm.contents.value);
    html = "<a href='../html/files/" + fm.files.value + "'>" + fm.files.value + "</a>";
    fm.contents.value += html;
    //alert(html);
  }
}

</script>
